import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "../db/database"; // your drizzle instance
import { username, openAPI, admin, organization } from "better-auth/plugins";

export const auth = betterAuth({
  csrf: false,
  database: drizzleAdapter(db, {
    provider: "sqlite", // or "mysql", "sqlite"
  }),
  emailAndPassword: {
    enabled: true,
  },
  plugins: [username(), openAPI(), admin(), organization()],
  trustedOrigins: [process.env.BETTER_AUTH_URL || '', process.env.FRONT_END_URL || ''],
  advanced: {
    crossSubDomainCookies: {
            enabled: true,
            domain: process.env.DOMAIN,
        },
        defaultCookieAttributes: {
            secure: true,
            httpOnly: true,
            sameSite: "none",
            partitioned: true,
        },
  },
});
